from app import AppData
from parse import Parse
from fetch import AsyncRequest
import json

if __name__ == '__main__':
    app = AppData()
    app_msg, layout_result, field_list = app.get_one_info('笔趣阁')
    field_dict = {}
    for layout in layout_result:
        for field in field_list:
            layout_id = int(field[-3])
            if layout_id == int(layout[0]):
                field_dict[field[1]] = field[2]

        parser = Parse(item=field_dict)
        urls = [layout[2].format(i) for i in range(1, 10)] if layout[2] != 'auto' else []
        parser_function = parser.parse_list
        req = AsyncRequest(
            url_list=urls,
            parse_func=parser_function,
            method=layout[3],
            encoding=app_msg[6],
            headers=json.loads(app_msg[5])
        )
        req.run()
